<template>
  <view class="interview-detail-page">
    <!-- 顶部导航 -->
    <view class="top-bar">
      <view class="back-btn" @click="navigateBack">
        <image class="back-icon" src="/static/icons/left.png"></image>
      </view>
      <text class="page-title">面试详情</text>
    </view>

    <!-- 头部信息卡片 -->
    <view class="header-card">
      <!-- 公司Logo（固定默认图） -->
      <image 
        class="company-logo" 
        src="/static/logos/chuanyi.png"
      ></image>
      <!-- 右侧信息容器 -->
      <view class="info-wrap">
        <view class="company-info">
          <text class="company-name">{{ item.company }}</text>
          <view class="hr-info">
            <!-- HR头像（接口headIcon） -->
            <image 
              class="hr-avatar" 
              :src="item.hrLogo ? item.hrLogo : '/static/avatar/avatar.png'"
            ></image>
            <text class="hr-name">{{ item.hrName }}</text>
          </view>
        </view>
        <text class="interview-time">面试时间：{{ item.time }}</text>
      </view>
    </view>

    <!-- 详情卡片 -->
    <view class="detail-card">
      <view class="detail-item">
        <text class="label">职位</text>
        <text class="value">{{ item.position || '暂无职位信息' }}</text>
      </view>
      <view class="detail-item">
        <text class="label">联系人</text>
        <text class="value">{{ item.contact || '暂无联系人信息' }}</text>
      </view>
      <view class="detail-item">
        <text class="label">地点</text>
        <text class="value">{{ item.location || '暂无地址信息' }}</text>
      </view>
      <view class="detail-item">
        <text class="label">状态</text>
        <text class="value" :style="{'color': item.statusColor}">{{ item.interviewStatusText }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import { getInterviewDeta } from '@/api/user.js'
export default {
  data() {
    return {
      bookingId: null,
      item: {
        company: '',
        hrLogo: '',
        hrName: '',
        time: '',
        position: '',
        contact: '',
        location: '',
        interviewStatus: 0,
        interviewStatusText: '',
        statusColor: ''
      }
    };
  },
  onLoad(val) {
    if (val.bookingId) {
      this.bookingId = val.bookingId;
      this.getInterviewDetailaka();
    } else {
      uni.showToast({ title: '参数错误，无法获取面试详情', icon: 'none' });
    }
  },
  methods: {
    getInterviewDetailaka() {
      getInterviewDeta({ bookingId: this.bookingId }).then(res => {
        if (res.code === 200 && res.data) {
          const apiData = res.data;
          this.item = {
            company: apiData.companyName || '暂无公司名称',
            hrLogo: apiData.headIcon,
            hrName: apiData.hrName || '暂无HR信息',
            time: apiData.interviewTime || '暂无面试时间',
            position: apiData.recruitName || '',
            contact: apiData.hrName || '',
            location: apiData.interviewAddress || '',
            interviewStatus: apiData.interviewStatus || 0,
            interviewStatusText: this.getStatusText(apiData.interviewStatus),
            statusColor: this.getStatusColor(apiData.interviewStatus)
          };
        } else {
          uni.showToast({ title: '未获取到面试详情', icon: 'none' });
        }
      }).catch(err => {
        console.error('获取面试详情失败：', err);
        uni.showToast({ title: '请求失败，请稍后重试', icon: 'none' });
      });
    },

    getStatusText(status) {
      const statusMap = {
        0: '未面试',
        1: '已面试',
        2: '已取消',
        3: '进行中',
        default: '未知状态'
      };
      return statusMap[status] || statusMap.default;
    },

    getStatusColor(status) {
      const colorMap = {
        0: '#86796a',
        1: '#14fb42',
        2: '#d10b47',
        3: '#e7db32',
        default: '#999'
      };
      return colorMap[status] || colorMap.default;
    },

    navigateBack() {
      uni.navigateBack();
    }
  }
};
</script>

<style scoped>
.interview-detail-page {
  background: linear-gradient(135deg, #fdeeff, #e6f7ff); 
  min-height: 100vh;
  padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
}

.top-bar {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.8);
  padding-top: env(safe-area-inset-top); /* 适配刘海屏 */
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 8px;
}

.back-btn {
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255,255,255,0.8);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  margin-right: 12px;
}

.back-icon { 
  width: 20px; 
  height: 20px; 
}

.page-title { 
  font-size: 20px; 
  font-weight: 700; 
  color: #333; 
}

.header-card {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.company-logo {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  margin-right: 16px;
  background: #f5f5f5;
}

.hr-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-right: 8px;
  background: #eee;
}

.company-name { 
  font-size: 18px; 
  font-weight: 600; 
  color: #ff6b6b; 
  margin-right: 8px; 
}

.hr-name { 
  font-size: 14px; 
  color: #666; 
}

.interview-time { 
  font-size: 14px; 
  color: #999; 
  margin-top: 8px; 
}

.detail-card {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.detail-item {
  display: flex;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid #f2f2f2;
}

.detail-item:last-child { 
  border-bottom: none; 
}

.label { 
  font-size: 15px; 
  color: #666; 
  width: 60px; 
}

.value {
  font-size: 15px;
  color: #333;
  text-align: right;
  flex: 1;
  white-space: normal;
  word-break: break-all;
}
</style>
